package com.tenbent.product.center.insures.service.impl;

import com.tenbent.product.base.service.impl.BaseServiceImpl;
import com.tenbent.product.center.insures.bo.SafeguardPackage;
import com.tenbent.product.center.insures.dto.SafeguardPackageDetailDto;
import com.tenbent.product.center.insures.dto.SafeguardPackageDto;
import com.tenbent.product.center.insures.mapper.SafeguardPackageMapper;
import com.tenbent.product.center.insures.service.SafeguardPackageDetailService;
import com.tenbent.product.center.insures.service.SafeguardPackageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by ThinkPad on 2017/8/21.
 */
@Service(value = "safeguardPackageServiceImpl")
public class SafeguardPackageServiceImpl extends BaseServiceImpl<SafeguardPackage> implements SafeguardPackageService {

	public SafeguardPackageServiceImpl() {
		this.setClazz(SafeguardPackage.class);
	}

	@Autowired
	private SafeguardPackageMapper safeguardPackageMapper;

	@Autowired
	@Qualifier("safeguardPackageDetailServiceImpl")
	private SafeguardPackageDetailService safeguardPackageDetailService;

	@Override
	public List<SafeguardPackageDto> findSafeguardPackageByProductId(Integer productId) {

		SafeguardPackage query = new SafeguardPackage();
		query.setProductId(productId);
		List<SafeguardPackageDto> list = change.changesToDTOList(this.queryObj(query), SafeguardPackageDto.class);
		for (SafeguardPackageDto safeguardPackage : list) {
			List<SafeguardPackageDetailDto> detailDtos = safeguardPackageDetailService
					.findSafeguardPackageDetailByCode(safeguardPackage.getPackageCode());
			if (safeguardPackage.getSafeguardPackageDetails() == null) {
				safeguardPackage.setSafeguardPackageDetails(detailDtos);
			}
		}
		return list;
	}
}
